class Solution {
public:
  // 滑动窗口
    int lengthOfLongestSubstring(string s) {
       size_t size = s.size();
       if(size <= 1)  return size;
       char hash[256] = {0};
       int maxlen = -1;
       for(int l = 0, r = 0; r < size; ++r){
           hash[s[r]] += 1;   // 标记出现过的字符
           while(hash[s[r]] > 1){ // 遇到重复字符
               hash[s[l++]] -= 1;   // 窗口左边收缩
           }
           int len = r - l + 1;
           maxlen = maxlen>len ? maxlen : len;
       }
       return maxlen;
    }
};